﻿using RentalIService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RentalDTO;

namespace RentalManagement.Controllers
{
    public class lanlordController : Controller
    {

        //IOC构造函数调用[第二种调用方式]
        private readonly IServicelandlordTenant _lanlordService;
        private readonly IServiceRole _Role;
        public lanlordController(IServicelandlordTenant lanlordService, IServiceRole serviceRole)
        {
            _lanlordService = lanlordService;
            _Role = serviceRole;
        }

        //数据展示
        public ActionResult Index()
        {
            ViewBag.role = _Role.SelectRoleID("F");
            return View();
        }
        //显示分页
        public ActionResult Selectlanlord(int offset, int limit, string sort, string order, string name)
        {
            int count = 0;//总数据量
            if (String.IsNullOrWhiteSpace(sort))
            {
                sort = "Id";
            }
            var lst = _lanlordService.Selectlanlord(offset, limit, sort, order, name, ref count);
            return Json(new { total = count, rows = lst }, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public ActionResult RDel(List<string> ids)
        {
            bool rDel = _lanlordService.RDel(ids);
            return Content(rDel ? "Y" : "");
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <param name="sex"></param>
        /// <param name="birthDay"></param>
        /// <param name="nativePlace"></param>
        /// <param name="address"></param>
        /// <param name="tel"></param>
        /// <param name="cardId"></param>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public ActionResult Add(string id, string name, int sex, DateTime birthDay, string nativePlace, string address, string tel, string cardId, string password, string email, string roleId)
        {
            bool add = _lanlordService.Add(name, sex, birthDay, nativePlace, address, tel, cardId, password, email, roleId);

            return Content(add ? "Y" : "");
        }

        public ActionResult Edit(landlordTenantDTO model)
        {
            bool edit = _lanlordService.Edit(model);
            return Content(edit ? "Y" : "");

        }

    }
}